package com.loveprogrammer.eternity.skill.support.skills.monster;

import com.loveprogrammer.eternity.enums.AttackTypeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.model.attack.AttackEntity;
import com.loveprogrammer.eternity.model.attack.AttackResult;
import com.loveprogrammer.eternity.skill.support.skills.AbstractSkill;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @version 1.0.0
 * @description: 寒冰球 冰系法术攻击
 * @author: eric
 * @date: 2022-08-16 16:53
 **/
public class SkillFrozenBall extends AbstractSkill {

    public SkillFrozenBall(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();

        Character single = findSingleAttacker(defences, true);
        // 造成冰冻伤害 并造成溅射伤害 35%
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ")
                .append(single.getName())
                .append(" 并对其他角色造成溅射伤害25% \n");
        int power = getHarm(character);
        // 暴击检测 提升200%的伤害 几率 技巧 + 500 / 技巧 + 6000
        boolean crit = false;
        int percents = (character.getTechnique() + 500) * 100 / (character.getTechnique() + 6000);
        if(new Random().nextInt(100) < percents){
            power = power * 2;
            crit = true;
        }

        for (Character defence : defences) {
            if(defence == single) {
                AttackResult attackResult = defence.defence(new AttackEntity(this, power, AttackTypeEnum.ICE));
                computeHarm(builder, crit, defence, attackResult, character, attack, defences);
            }
            else{
                int harmReal = (int) (power * 0.25);
                AttackResult attackResult = defence.defence(new AttackEntity(this, harmReal, AttackTypeEnum.ICE));
                computeHarm(builder, crit, defence, attackResult, character, attack, defences);
            }
        }
        result.setValue(new ArrayList<>(defences));
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getMagic() * 1.1 * ((100 + getBaseHarm() + getLevel() * 2) / 100));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    @Override
    public boolean check(Character character) {
        if(restInterval() <= 0) {
            return true;
        }
        return false;
    }

    @Override
    public int opportunityPassive() {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每3级升一级
        if(characterLevel % 3 == 0){
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        return 20;
    }
}
